package com.edu.his.service.impl.impl;

import com.edu.his.domain.Common;
import com.edu.his.mapper.CommonMapper;
import com.edu.his.service.CommonService;
import com.edu.his.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 描述：
 * 创建人：飘
 * 创建时间：2024/12/25
 **/
@Service
public class CommonServiceImpl implements CommonService {
    @Autowired
    private CommonMapper commonMapper;
    @Override
    public R selectByRegiserId(Integer registerId) {
        List<Common> listAll=new ArrayList<>();//保存检查，检验，处置，处方
//
//            #1.检查
     List<Common> listCheck=this.commonMapper.selectCheckByRegiserId(registerId);
//            #2.检验
//            select * from  inspection_request
//            #3.处置
//            select * from  disposal_request
//            #4.处方
        List<Common> listPrescription=this.commonMapper.selectPrescriptionByRegiserId(registerId);
        //List<Common> listDrug=this.commonMapper.selectCheckByRegiserId(registerId);
        //集合中添加集合(相同类型的的集合)
        if(listCheck!=null && listCheck.size()>0)
         listAll.addAll(listCheck);

        if(listPrescription!=null && listPrescription.size()>0)
            listAll.addAll(listPrescription);
        return R.success(200,"查询成功",listAll);
    }

    @Override
    public R updateState(List<Common> list) {
        for(Common item:list)
        {
            if(item.getItemType().equals("检查"))
                this.commonMapper.updateStateCheckRequest(item.getId());
            if(item.getItemType().equals("检验"))
                this.commonMapper.updateStateinspectionRequest(item.getId());
            if(item.getItemType().equals("处置"))
                this.commonMapper.updateStateDisposalRequest(item.getId());
            if(item.getItemType().equals("处方"))
                this.commonMapper.updateStatePrescriptionRequest(item.getId());
        }
        return R.success(200,"状态修改成功",1);
    }


}
